#!/usr/bin/python

# Python script for Nepomuk firefox
print "Script showAllClass.py in the position"

#get the argument from parent window
arg0 = window.arguments[0]

LIST_CLASS = document.getElementById("allClassList")
document.getElementById("uriLabel").setAttribute("value",arg0)

# attach TheNepomukWhisperer to the document
from the_nepomuk_whisperer import TheNepomukWhisperer
document.NEPO = TheNepomukWhisperer(ONTOLOGIES_STORAGE_FILE)
# get all the Classes and subClasses
subClasses = document.NEPO.pimo.getSubClassArray(arg0)
#Clear the List
while LIST_CLASS.childNodes.length != 1:
	LIST_CLASS.removeChild(LIST_CLASS.lastChild)
#Fill in the List
for (uri, name) in subClasses:
	row = document.createElement('listitem')
	row.setAttribute('value', uri)
	row.setAttribute('tooltiptext', uri)

	cell = document.createElement('listcell')
	cell.setAttribute('label', name)
	row.appendChild(cell)

	LIST_CLASS.appendChild(row)

theClass = ""

def clickOnClass():
	theClass = LIST_CLASS.selectedItem.getAttribute("value")
	document.getElementById("classUri").setAttribute("value",theClass)

def clearTextName():
	document.getElementById("textStateName").value=""

def clearTextDesc():
	document.getElementById("textStateDesc").value=""

def checkName():
	#disable the save statement button if no name entered
	if theClass=="":
		document.getElementById("saveStatBT").disabled = (document.getElementById("textStateName").value=="")

def saveStatement():
	theClass = LIST_CLASS.selectedItem.getAttribute("value")
	stateName = document.getElementById("textStateName").value
	stateDesc = document.getElementById("textStateDesc").value
	print "saving statement with name: " + stateName
	if stateDesc == "":
		document.NEPO.pimo.addStatement(theClass,stateName)
	if stateDesc == "Input the Description(optional)...":
		document.NEPO.pimo.addStatement(theClass,stateName)
	else:
		document.NEPO.pimo.addStatement(theClass,stateName,stateDesc)
	window.close()